#!/usr/bin/env bash

IFS=$'\n'
#tmpstring=$1
if [[ `echo ${1:(-1)}` == "," ]]; then
    tmpstring=`echo ${1%,*}`
    shift
    files=($(fd -H $tmpstring -t f $FDEXCLUDE --search-path={$HOME,/etc/}| fzf -q $tmpstring $@))
    unset tmpstring
elif [[ `echo ${1:(-1)}` == "." ]]; then
    tmpstring=`echo ${1%.*}`
    shift
    files=($(fd -t f --max-depth=1 -H --search-path=$HOME|fzf -q $tmpstring $@))
    unset tmpstring
else
    files=($(fd -t f $1 $FDEXCLUDE --search-path={$HOME,$HOME/.local,$HOME/.config} |fzf -q $@ ))
fi
[[ -n "$files" ]] && vim "${files[@]}"
unset files tmpcmd
